home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13631 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Question on pointers
  5. Date: Tue, 09 Apr 96 12:02:31 GMT
  6. Organization: none
  7. Message-ID: <829051351snz@genesis.demon.co.uk>
  8. References: <1996Apr8.233330.139449@forest>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <1996Apr8.233330.139449@forest> ebromber@forest.drew.edu  writes:
  15.  
  16. >In a program there is an array of structs. One of the headers for a 
  17. >function says void pop(stack *).  My question is shouldn't there be a name 
  18. >or identifier after the asterisk?
  19.  
  20. If it is just a declaration of the function then, no, you don't need to
  21. name the parameters. All a declaration such as this does is provide type
  22. information so that in a function call the compiler can validate the
  23. arguments, perform any necessary conversions and generate the correct call
  24. code. For a function definition i.e. where you define a function body you
  25. must name the parameters.
  26.  
  27. void pop(stack *);       /* Simple (prototyped) declaration */
  28.  
  29. /* The function definition */
  30.  
  31. void pop(stack *sp)
  32. {
  33.     /* Code using sp */
  34. }
  35.  
  36. >My friend says that it is the address of 
  37. >a stack in the array. If this is true, how could I access the thing 
  38. >pointed to?
  39.  
  40. In the example above you can refer to the thing pointed to using *sp in
  41. the function.
  42.  
  43. >Here are some lines which define a stack
  44. >
  45. >typedef struct item item;
  46. >struct item {
  47. >        struct item *next;
  48. >        char c;
  49. >        }
  50. >typedef item *stack;
  51.  
  52. -- 
  53. -----------------------------------------
  54. Lawrence Kirby | fred@genesis.demon.co.uk
  55. Wilts, England | 70734.126@compuserve.com
  56. -----------------------------------------
  57.